const { validationResult } = require('express-validator');

function validateChecks(checks) {
    return async function (req, res, next) {
        for (let check of checks) {
            await check.run(req);
        }
        const errors = validationResult(req);
        if (!errors.isEmpty()) {
            let messages = errors.array().map(error => error.msg);
            return res.createResponse(400, messages)
        }
        next();
    }
}

module.exports = validateChecks;